<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>03-事件注册中的this</title>
</head>
<body>
  <div id="app">
    <h1>vue的例子</h1>
    <p>{{msg}}</p>
    <input type="button" value="按钮" @click="btnHandler">
  </div>
  <script src="../js/vue.js"></script>
  <script>
    Vue.config.productionTip = false; // 关闭生产提示
    const vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello'
      },
      methods: {
        btnHandler() {
          // methods中的事件处理程序中当前的实例对象要使用this来表示
          // 也就是说this就是当前有实例对象vm
          // console.log(this.msg)
          console.log(vm.msg)
        }
      }
    })

    // 单击按钮实现反转

    const obj = {
      msg: 'HellowORLD',
      btnHandler() {
        console.log(this.msg)
      }
    }
  </script>
</body>
</html>